<%
/**
 * append 为角色分配多个用户弹出框
 * 
 * @author   张彬
 * @version v1.0
 * @date     2011-10-17
 * @since   JDK1.6
 */
%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="at" uri="/WEB-INF/util_tag.tld"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title><s:text name="sysRole.append.title"></s:text></title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta content="no-cache" http-equiv="Pragma" />
		<meta content="no-cache" http-equiv="Cache-Control" />
		<meta content="0" http-equiv="Expires" />
		<meta name="GENERATOR" content="MSHTML 8.00.6001.18854" />
		<link rel="stylesheet" id="dialog" type="text/css" href="<at:url css="dialog.css"/>" />
		<link rel="stylesheet" id="banner" type="text/css" href="<at:url css="banner_button.css"/>" />
		<script type="text/javascript" src="${rootPath}/Common/Js/jquery.js"></script>
		<script type="text/javascript" src="${rootPath}/Common/Js/common.js"></script>
		<script type="text/javascript" src="<at:url js="banner_button.js"/>"></script>
		<script type="text/javascript" src="<at:url js="dialog.js"/>"></script>
		<script type="text/javascript" src="${rootPath}/Common/Js/My97DatePicker/WdatePicker.js" defer="defer"></script>
		<script type="text/JavaScript">	
		    var MyObject = window.dialogArguments;
		    function roleSelected(checkbox)
		    {         
			    var TheName = checkbox.getAttribute("thetext");
			    var TheID = checkbox.value;
			    var lis=document.getElementById("SelectedList");
			    var IfAdd=true;     //设置一个布尔变量来控制是否把当前人员姓名加入到已选人员列表中
			    if (checkbox.checked){
				    for (var i=0;i<lis.options.length;i++){
					    if (lis.options[i].value==TheID){
						    IfAdd=false;				
						    break;
				        }
				    }
			    }
			    else{ 
			        //document.all.checkall.checked=false;
				    IfAdd=false;
				    for (var i=0;i<lis.options.length;i++){
					    if (lis.options[i].value==TheID){
						    lis.options[i] = null;
						    break;				
					    }
				    }
			    }
			    if(IfAdd){
				    lis.options.length=lis.options.length+1;
				    lis.options[lis.options.length-1].text = TheName;
				    lis.options[lis.options.length-1].value = TheID;
			    }
			    refreshSelectedListStr();
		    }
				    
			function okClick() 
		    {	
		        var resultList = "";
		        var SelectedPeopleList=document.getElementById("SelectedList");
			    if ( SelectedPeopleList.options.length > 0 ){
				    for ( i = 0; i < SelectedPeopleList.options.length; i++ )
				    {
		                if(SelectedPeopleList.options[i].text!="" && SelectedPeopleList.options[i].text!=null){
		                    resultList=resultList + SelectedPeopleList.options[i].value;
		                    if(i < SelectedPeopleList.options.length - 1){
		                        resultList += ",";
		                    }
				        }
				    }
					startRequest("SysRole!appendUser.action?page=${page}&funId=${funId}&object.id=${object.id}", function(text){window.close();}, {ids:resultList});		        
			    }
		        else
		        {  
		            alert('<s:text name="js.common.noChoise"></s:text>');
		        }
		    }
		    
		    function doCancel()
		    {
		        window.close();
		    } 
		    
		    function init(){
		    	var lis = document.getElementById("SelectedList");
		        var jsonStr = document.queryForm.jsonStr.value;
		        if(null != jsonStr && jsonStr != ""){
		        	var jsonObjList = eval('(' + jsonStr + ')');
			        for(var i = 0;i < jsonObjList.length;i++){
					 	lis.options.length = lis.options.length+1;
					  	lis.options[lis.options.length-1].text = jsonObjList[i].name;
				    	lis.options[lis.options.length-1].value = jsonObjList[i].id;
			        }
		        }
		    }
		
			function refreshSelectedListStr(){
				var lis=document.getElementById("SelectedList");
			   	var jsonObj = "[";
			   	for(var i = 0;i < lis.options.length;i++){
			       	if(jsonObj.length > 1)
			       		jsonObj += ",";
					jsonObj += '{"id":"' + lis.options[i].value+'","name":"'+lis.options[i].text + '"}'; 
				}   
				jsonObj += "]"; 
				document.queryForm.jsonStr.value=jsonObj;
			}
		
			jQuery(document).ready(function(){
				init();
			});
		</script>
		<base target="_self" />
	</head>

	<body>
		<form action="SysRole!append.action" name="queryForm" method="post">
			<input type="hidden" name="page" value="${page}" />
			<input type="hidden" name="order" value="${order}" />
			<input type="hidden" name="vQuery" value="${vQuery}" />
			<input type="hidden" name="jsonStr" value='${jsonStr}' />
			<input type="hidden" name="object.id" value="${object.id}" />
			<div class="dialog_mutil2">
				<div style="height: 372px">
					<div class="banner_div">
						<ul class="banner_button">
							<li>
								<a href="javascript:void(0)" onclick="multiQuery();"><span><s:text name="sysRole.append.query"></s:text></span> </a>
							</li>
						</ul>
					</div>
					<div class="clear_div"></div>
					<div id="query_bar" style="display:${vQuery==0?'none':''};" class="queryTab">
						<table border="0">
							<tr>
								<td>
									<table border="0">
										<tr>
											<td>
												<s:text name="sysRole.append.userName"></s:text>
											</td>
											<td>
												<input type="text" name="su.name" value="${su.name}" />
											</td>
											<td>
												<s:text name="sysRole.append.usableFlag"></s:text>
											</td>
											<td>
												<select class="picklist" name="su.usableFlag.id">
													<option value="">
														<s:text name="sysRole.append.usableFlag"></s:text>...
													</option>
													<s:action name="SysCode!getCodeList" namespace="/Sys">
														<s:param name="codeType"><nobr>AccStatus</s:param>
													</s:action>
													<s:iterator value="#request['codeList']">
														<option value="${id}" ${id==su.usableFlag.id?'selected':'' }>
															${name}
														</option>
													</s:iterator>
												</select>
											</td>
										</tr>
									</table>
								</td>
								<td>
									<button type="submit" class="research_button" onclick="page.value=1">
										<nobr><s:text name="common.affirm"></s:text></nobr>
									</button>
								</td>
							</tr>
						</table>
					</div>
					<table width="100%" cellpadding="0" cellspacing="0" style="height: 100%;">
						<tr>
							<td valign="top">
								<div class="dialog_div">
									<table cellspacing="0" cellpadding="0" width="100%" class="dialog_table">
										<thead class="dialog_thead">
											
												<tr>
													<th align="center" width="10%">
														<input id="checkAll" title="<s:text name="sysRole.append.select"></s:text>" type="checkbox" name="checkAll" onclick="selectAll('checkOne')" />
													</th>
													<th width="30%">
														<s:text name="sysRole.append.organ"></s:text>
													</th>
													<th width="30%">
														<s:text name="sysRole.append.person"></s:text>
													</th>
													<th width="30%" onclick="orderby('name')">
														<s:text name="sysRole.append.userName"></s:text>
													</th>
												</tr>
										</thead>
										<tbody class="dialog_tbody">
											<s:iterator value="#request['pagelist'].content" status="status">
												<tr id="tr${status.count}" onclick="rowclick(this)" onmouseover="rowover(this)" onmouseout="rowout(this)">
													<td id="userData" valign="middle" align="center">
														<input onclick="roleSelected(this)" id="checkOne" type="checkbox" thetext="${userName}" name="checkOne" value="${id}" />
													</td>
													<td title="${orgName}">
														${orgName}
													</td>
													<td title="${empName}">
														${empName}
													</td>
													<td title="${userName}">
														${userName}
													</td>
												</tr>
											</s:iterator>
										</tbody>
										<tfoot class="dialog_tfoot">
											<tr>
												<td colspan="4">
													<div class="list_bottom">
														<div class="all_text">
															<span class="inverse_button" onclick="selectReverse('checkOne')">
																反选
															</span>
														</div>
														<div>
															<at:page />
														</div>
													</div>
												</td>
											</tr>
										</tfoot>
									</table>
								</div>
							</td>
							<td valign="top" style="width: 20px;">
								<div class="arrow2">
									<div class="arrow_top" onclick="moveUp(document.all.SelectedList);"></div>
									<div class="arrow_middle" onclick="removeAll(document.all.SelectedList);"></div>
									<div class="arrow_bottom" onclick="moveDown(document.all.SelectedList);"></div>
								</div>
							</td>
							<td valign="top" style="width: 130px">
								<div class="select_lump3">
									<div class="select_title">
										已选用户
									</div>
									<div>
										<select multiple="multiple" id="SelectedList" ondblclick="removeSelect(this);" size="5"
											style="width: 130px; height: 343px; margin: 0px; padding: 0px;">
										</select>
									</div>
								</div>
							</td>
						</tr>
					</table>
				</div>
				<div class="dialog_button dialog_button5">
					<div class="button_left button_left5" onclick="okClick();">
						确定
					</div>
					<div class="button_right button_right5" onclick="doCancel();">
						取消
					</div>
				</div>
			</div>
		</form>
	</body>
</html>
